import { Component, instantiate, Node, Prefab, resources, Vec3 } from "cc";
import { ResMgr } from "../../../new/common/ResMgr";
import { TopBarUI } from "../TopBarUI";

/**
 * 头顶血条
 */
export class HpComp extends Component {
    private hpBarUI: Node;
    public hpBar: TopBarUI
    init() {
        resources.load(ResMgr.getHpPrefab(), Prefab, null, this.onHpLoad.bind(this));

    }

    /**加载头顶血条 */
    onHpLoad(err, data): void {
        if (err) {
            console.log(err)
        } else {
            this.hpBarUI = instantiate(data);
            this.hpBarUI.setPosition(new Vec3(0, 230, 0));
            this.node.addChild(this.hpBarUI);
            this.hpBar = this.hpBarUI.getComponent(TopBarUI);
            this.hpBar.setValue(1);
        }
    }

    /**设置血条，0-1
     * 
     */
    setValue(value: number) {
        this.hpBar.setValue(value);
    }


}